#!/bin/sh

cd `dirname $0`/.. || { echo --- error changing to the inet root directory ---; exit 1;}
INET_ROOT=`pwd`

# tag and release names...
relname=inet-`$INET_ROOT/_scripts/get_version`
escaped_relname=inet-`$INET_ROOT/_scripts/get_version | sed 's/\./\\\\./g'`

# check tag format
echo "About to add --- $relname released --- line to ChangeLogs"
echo "Enter to continue..."
read tmp

head="====== inet-3.x ======"

# update ChangeLog files. (remove earlier marker line if exists, plus blank line below it)
today=`date '+20%y-%m-%d'`
line="$today  ------ $relname released ------"
pattern="^[0-9-]\+  ------ $escaped_relname released ------"
echo "Finding ChangeLogs..."
changelogs=`find . -name ChangeLog`
echo "Updating ChangeLogs..."
for i in $changelogs; do
    echo "$head" > $i.b
    echo "" >> $i.b
    echo "$line" >> $i.b
    echo "" >> $i.b
    sed "/$head/{N;d;}" $i | sed "/$pattern/{N;d;}" >> $i.b || exit 1
    mv $i.b $i || exit 1
done
echo "Done"
